package com.educate.commonutils;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * 统一返回结果得类
 */
@Data
public class ResultOne {
//    public static ResultOne ok;
    @ApiModelProperty(value = "是否成功")
    private Boolean success;
    @ApiModelProperty(value = "返回码")
    private Integer code;
    @ApiModelProperty(value = "返回消息")
    private String message;
    @ApiModelProperty(value = "返回数据")
    private Map<String, Object> data = new HashMap<String, Object>();

    //构造方法私有
    private ResultOne(){}
    //链式编程

    public static ResultOne ok(){
        ResultOne result = new ResultOne();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS);
        result.setMessage("成功");
        return result;
    }

    public static ResultOne error(){
        ResultOne result = new ResultOne();
        result.setSuccess(false);
        result.setCode(ResultCode.ERROR);
        result.setMessage("失败");
        return result;
    }

    public ResultOne success(Boolean success){
        this.setSuccess(success);
        return this;
    }
    public ResultOne message(String message){
        this.setMessage(message);
        return this;
    }
    public ResultOne code(Integer code){
        this.setCode(code);
        return this;
    }
    public ResultOne data(String key, Object value){
        this.data.put(key, value);
        return this;
    }
    public ResultOne data(Map<String, Object> map){
        this.setData(map);
        return this;
    }

    }
